package com.handl.springcloud.controller;

import com.handl.springcloud.dto.User;
import com.handl.springcloud.service.UserService;
import org.springframework.web.bind.annotation.*;

/**
 * Created by handl on 2017/11/6.
 *
 * 因为引入了抽象抽离的服务项目，则可以直接继承定义好的service，并实现即可
 * 1.RequestMapping也一样被继承，因此不需要在此controller再写
 * 2.此controller需要定义@RestController，声明为controller服务
 *
 */
@RestController
public class UserController implements UserService{
    //注意：不需要写RequestMapping
    //要对象抽象抽离service中的@RequestParam，@RequestBody，@RequestHeader
    @Override
    public String getHttpParam(@RequestParam("name") String name) {
        return "hello " + name;
    }

    @Override
    public String getHttpHeard(@RequestHeader("des") String des) {
        return "ok,i like you des";
    }

    @Override
    public User getHttpBody(@RequestBody User user) {
        user.setAge(user.getAge()+1);
        user.setName(user.getName()+",hello");
        return user;
    }


    //下面是不用抽象抽离服务，直接让消费来请求的接口
    //不是继承的接口，完成当前自己提供，要有RequstMapping
    @RequestMapping("self1")
    public String self1(@RequestParam("name") String name){
        return "hello " + name +",self";
    }
    @RequestMapping("self2")
    public String self2(@RequestHeader("des") String des) {
        return "ok,i like you des, self";
    }
    @RequestMapping("self3")
    public User self3(@RequestBody User user) {
        user.setAge(user.getAge()+1);
        user.setName(user.getName()+",hello,self");
        return user;
    }
}
